package org.itboys.portal.service;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import javax.annotation.Resource;

import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.portal.entity.Feedback;
import org.springframework.stereotype.Service;

/** 
 * @author 作者 huml 
 * @version 创建时间：2016-4-7 下午1:54:38 
 * 意见反馈 
 */
@Service
public class FeedbackService extends BasePortalService<Feedback, Long> {

	private static final long serialVersionUID = -5820267350090135937L;
	
	@Resource(name="portalDS")
	private MongoDataSource feedbackDataSource;

	@Override
	protected MongoDataSource getMongoDataSource() {
		return feedbackDataSource;
	}

	@Override
	protected Class<Feedback> getEntityClass() {
		return Feedback.class;
	}
	
	/**
	 * 更新操作
	 * @param entity
	 * @return
	 */
	public <T> void modifyNotNull(Feedback bean){
		Field[] Fields = bean.getClass().getDeclaredFields();
		Feedback data = getById(bean.getId());
		try {
			for (Field field : Fields)
			{
				if (!Modifier.isFinal(field.getModifiers()))
				{
					field.setAccessible(true);
					if (field.get(bean) != null /*&& !field.get(bean).toString().equals("")*/)
					{
						field.set(data, field.get(bean));
					}

				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		super.update(data);
	}
}
